package com.example.myapplication.ContentTest;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.example.myapplication.R;

public class DictionaryActivity extends AppCompatActivity {
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dictionary_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("生词本管理");
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    Init();
  }

  private void Init() {
    Button infoButton = (Button) findViewById(R.id.info_button);
    Button addButton = (Button) findViewById(R.id.add_button);
    infoButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToSearchPage();
      }
    });
    addButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToAddPage();
      }
    });
  }

  private void JumpToAddPage() {
    Intent intent = new Intent(this, DictionaryAddActivity.class);
    startActivity(intent);

  }

  private void JumpToSearchPage() {
    Intent intent = new Intent(this, DictionaryInfoActivity.class);
    startActivity(intent);

  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        GoBack();
    }
    return true;
  }

  private void GoBack() {
    finish();
  }
}
